//
// NetworkIO.h
//
// $Id: //base/include/Proactor.h
//
// Library: base
// Package: Proactor
// Module:  Proactor
//
// Definition of the Proactor class.
//
// Copyright (c) 2012-2012, iGuard.
// doitsjz@163.com	jelin
//


#ifndef PROACTOR_INCLUDED
#define PROACTOR_INCLUDED

#include "BaseSocket.h"
#include "BaseTimer.h"
#include <pj/timer.h>
/**
	proactor implement
*/

class BaseSocket;
class BaseTimer;

class BASE_API Proactor
{
public:
	Proactor(int max_fd);
	~Proactor();
public:
	int HandleEvents(pj_time_val *timeout);
    int RegisterHandle(BaseSocket* p_sock);
	//for timer
	bool DoTimer(BaseTimer* pTimer,pj_time_val delay);
	bool UndoTimer(BaseTimer* pTimer);
protected:
	pj_ioqueue_t *ioqueue;
	pj_timer_heap_t *th_;
	pj_pool_t *pool;
    pj_caching_pool caching_pool;
	friend class TcpSocket;
	friend class UdpSocket;
};


#endif